﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Website
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private Voorstelling v;
        private decimal totalprice;
        private List<int> gebruikteStoelen;
        private List<int> gebruikteRijen = new List<int>();

        protected void Page_Load(object sender, EventArgs e)
        {
            gebruikteStoelen = new List<int>();

            v = (Voorstelling)Session["voorstelling"];
            totalprice = 0;

            if (v == null)
            {
                Response.Redirect("StartPagina.aspx");
            }
            else
            {
                initComponents();
                showPriceOverview();
            }
        }

        private void initComponents()
        {
            FilmPosterInfo filmPosterInfo = (FilmPosterInfo)LoadControl("FilmPosterInfo.ascx");
            filmPosterInfo.setgetFilm = v.Film;
            Panel_FilmPosterInfo.Controls.Add(filmPosterInfo);
        }

        //Het prijzenoverzicht deel.
        private void showPriceOverview()
        {
            var tickettypes = from t in Module.database.Tickettypes
                              select t;

            LabelCount.Visible = true;
            LabelType.Visible = true;
            LabelPrice.Visible = true;

            //De labels alleen aanzetten en invullen bij de tickettypes die de klant ook wilt kopen.
            foreach (var t in tickettypes)
            {
                switch (t.naam)
                {
                    case "3D Bril":
                        int driedglasses = (int)Session["3dglasses"];
                        if (driedglasses > 0)
                        {
                            LabelNumber3D.Visible = true;
                            LabelType3D.Visible = true;
                            LabelPrice3d.Visible = true;

                            LabelNumber3D.Text = Convert.ToString(driedglasses) + "x";
                            LabelType3D.Text = t.naam;
                            LabelPrice3d.Text = String.Format("&euro; {0:0.00}", driedglasses * t.prijs);
                            totalprice += (driedglasses * t.prijs);
                        }
                        break;

                    case "50+":
                        int fiftyplus = (int)Session["50plus"];
                        if (fiftyplus > 0)
                        {
                            LabelNumberOldPeople.Visible = true;
                            LabelTypeOldpeople.Visible = true;
                            LabelPriceOldPeople.Visible = true;

                            LabelNumberOldPeople.Text = Convert.ToString(fiftyplus) + "x";
                            LabelTypeOldpeople.Text = t.naam;
                            LabelPriceOldPeople.Text = String.Format("&euro; {0:0.00}", fiftyplus * t.prijs);
                            totalprice += (fiftyplus * t.prijs);
                        }
                        break;

                    case "CJP/student":
                        int students = (int)Session["students"];
                        if (students > 0)
                        {
                            LabelNumberStudent.Visible = true;
                            LabelTypeStudent.Visible = true;
                            LabelPriceStudent.Visible = true;

                            LabelNumberStudent.Text = Convert.ToString(students) + "x";
                            LabelTypeStudent.Text = t.naam;
                            LabelPriceStudent.Text = String.Format("&euro; {0:0.00}", students * t.prijs);
                            totalprice += (students * t.prijs);
                        }
                        break;

                    case "kind":
                        int childeren = (int)Session["childeren"];
                        if (childeren > 0)
                        {
                            LabelNumberChild.Visible = true;
                            LabelTypeChild.Visible = true;
                            LabelPriceChild.Visible = true;

                            LabelNumberChild.Text = Convert.ToString(childeren) + "x";
                            LabelTypeChild.Text = t.naam;
                            LabelPriceChild.Text = String.Format("&euro; {0:0.00}", childeren * t.prijs);
                            totalprice += (childeren * t.prijs);
                        }
                        break;

                    case "volwassen":
                        int adults = (int)Session["adults"];
                        if (adults > 0)
                        {
                            LabelNumberAdult.Visible = true;
                            LabelTypeAdult.Visible = true;
                            LabelPriceAdult.Visible = true;

                            LabelNumberAdult.Text = Convert.ToString(adults) + "x";
                            LabelTypeAdult.Text = t.naam;
                            LabelPriceAdult.Text = String.Format("&euro; {0:0.00}", adults * t.prijs);
                            totalprice += (adults * t.prijs);
                        }
                        break;
                }
            }

            LabelPriceTotal.Text = String.Format("Totaal: &euro; {0:0.00}", totalprice);
        }

        protected void ButtonNext_Click(object sender, EventArgs e)
        {
            Session["totalprice"] = totalprice;

            if ((string)Session["bestelwijze"] == "Reserveren")
            {
                Response.Redirect("ReserveringEinde.aspx");
            }

            else
            {
                Response.Redirect("KaartjePrinten.aspx");
            }
        }
    }
}